<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/pages/common/taglib.jsp"%>
<%@ include file="../../back-common.jsp"%>
<%@ include file="/WEB-INF/pages/common/back-dialog.jsp"%>
<%@ taglib uri="http://displaytag.sf.net" prefix="display"%>
<script language="JavaScript" type="text/javascript">
	$(document).ready(function() {
		//将该角色已经拥有的资源选上
		<c:forEach items="${list}" var="selecFunc">
			$("#${selecFunc.id}").attr("checked",true);
		</c:forEach>
		
		var saveStatus = $("#saveStatus").val();
		if(saveStatus == 1) {
			layer.alert("保存成功!");
		}
	});
	
	function selectAll(checker, scope){
    if(scope){
            $('#' + scope + ' input').each(function() 
            {
            	$(this).prop("checked", checker.checked);
            });
    }
    else
    {
            $('input:checkbox').each(function() 
            {
                $(this).prop("checked", checker.checked)
            });
    }
}
	
	function checkForm(){
		var funLen = $('input[name=funcId]:checked').length
		if(funLen==0){
			layer.tips("至少选择一个权限！");
			return false;
		}
		return true;
	}
</script>
	<input type="hidden" value="${saveStatus}" id="saveStatus"/>
    <table class="${tableclass}" style="width: 100%">
    <thead>
    	<tr><th><strong class="am-text-primary am-text-lg">权限管理</strong> /  角色[${bean.name }]对应的权限列表 </th></tr>
    </thead>
    </table>
        <%@ include file="/WEB-INF/pages/common/messages.jsp"%>
<style type="text/css">
<!--
.group-item {
    display: block;
    float: left;
    font-size: 14px;
    width: 200px;
}

.w-150px {
    width: 150px;
}

.text-right {
    text-align: right;
}
-->
</style>
 
 <form:form  action="${contextPath}/admin/member/role/saveFunctionsToRole" id="form1" method="post" onsubmit="return checkForm();">
   <input type="hidden" name="roleId" value="${bean.id}">
   <table class="${tableclass}" style="width: 100%"> 
    <thead>
      <tr>
        <th class="text-right">菜单</th>
        <th>权限</th>
      </tr>
    </thead>
     <tbody>
    <c:if test="${not empty  authorizeSysFunctions}">
  	<tr>
      <th class="text-right w-150px">功能权限 <input type="checkbox" onclick="selectAll(this, 'sysFunction')" ></th>
      <td class="pv-10px" id="sysFunction">
      			<c:forEach items="${authorizeSysFunctions}" var = "authSysFunction">
		          <div class="group-item">
		          		<input type="checkbox"  value="${authSysFunction.id}"  id='${authSysFunction.id}'  name="funcId">
		         		 <span id="index-index" class="priv">${authSysFunction.note}</span>
		        </div>
			</c:forEach>
        </td>
    </tr>
  </c:if>   
  
  <c:forEach items="${resultFuncList}" var="resultFunc"  varStatus="status">
      <c:forEach items="${resultFunc.funcWrapperList}" var="funcWrapper"  >
    	<tr>
        	<th class="text-right w-150px">${funcWrapper.menuName} <input type="checkbox" onclick="selectAll(this, 'funcDiv${status.index}')"  ></th>
       		<td class="pv-10px" id="funcDiv${status.index}">
      			<c:forEach items="${funcWrapper.funcList}" var = "func">
		          <div class="group-item">
		          		<input type="checkbox"  value='${func.id}' id='${func.id}'  name="funcId">
		         		 <span id="index-index" class="priv">${func.note}</span>
		        </div>
			</c:forEach>
		</c:forEach>
        </td>
   	 </tr>
	</c:forEach>
  
     <tr>     
       <th class="text-right">全选
		<input onclick='selectAll(this, "")' type="checkbox"></th>
      	<td colspan="2">
	         <input  class="${btnclass}"  id="submit" type="submit" value="保存"></input> 
	         <input class="${btnclass} " onclick="window.location='${contextPath}/admin/member/role/query'" type="button" value="返回"></input>

      </td>
    </tr>
  </tbody></table>
     </form:form>